package com.bdqn.shequ.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.bdqn.shequ.common.validator.ValidatorUtils;
import com.bdqn.shequ.common.validator.group.AddGroup;
import com.bdqn.shequ.common.validator.group.UpdateGroup;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bdqn.shequ.modules.sys.entity.TcConventionCenterEntity;
import com.bdqn.shequ.modules.sys.service.TcConventionCenterService;
import com.bdqn.shequ.common.utils.PageUtils;
import com.bdqn.shequ.common.utils.R;

import javax.servlet.http.HttpSession;


/**
 * 会议中心表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-04-15 11:07:40
 */
@RestController
@RequestMapping("sys/tcconventioncenter")
public class TcConventionCenterController {
    @Autowired
    private TcConventionCenterService tcConventionCenterService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tcconventioncenter:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tcConventionCenterService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:tcconventioncenter:info")
    public R info(@PathVariable("id") Long id){
        TcConventionCenterEntity tcConventionCenter = tcConventionCenterService.getById(id);

        return R.ok().put("tcConventionCenter", tcConventionCenter);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tcconventioncenter:save")
    public R save(@RequestBody TcConventionCenterEntity tcConventionCenter, HttpSession session){
        ValidatorUtils.validateEntity(tcConventionCenter,  AddGroup.class);
        tcConventionCenter.setCreateTime(new Date());

        tcConventionCenterService.save(tcConventionCenter);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tcconventioncenter:update")
    public R update(@RequestBody TcConventionCenterEntity tcConventionCenter){
        ValidatorUtils.validateEntity(tcConventionCenter, UpdateGroup.class);
        tcConventionCenter.setUpdateTime(new Date());
        tcConventionCenterService.updateById(tcConventionCenter);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tcconventioncenter:delete")
    public R delete(@RequestBody Long[] ids){
        tcConventionCenterService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/selname")
    @ResponseBody
    public String selectConventionName(@RequestParam Map<String, Object> params){
        List<String> list = tcConventionCenterService.selectConventionName();
        return JSON.toJSONString(list);
    }


}
